<?php
namespace Admin\Controller;
use Model\AdminModel;
use Think\Log;

/**
 * Created by PhpStorm.
 * User: yanshaopeng
 * Date: 2018/9/9
 * Time: 11:35
 */
class UserController extends AdminBaseController{
    private $_db;
    public function __construct()
    {
        parent::__construct();
        $this->_db = new AdminModel();
    }

    public function login(){
        $this->display();
    }

    public function loginIn(){
        $user = I('post.user','');
        $pwd = I('post.pwd','');

        $w['user'] = $user;
        $f = 'id,passwd';
        $pwd_a = md5(md5($pwd).C('PWD_PREFIX'));
        $ret = $this->_db->findOne($w,$f);

        if(empty($ret)){
            $r_data = ['code'=>201,'msg'=>'用户不存在'];
            $this->ajaxReturn($r_data,'json');
        }elseif($ret['passwd'] != $pwd_a){
            $r_data = ['code'=>202,'msg'=>'密码错误'];
            $this->ajaxReturn($r_data,'json');
        }else{
            session('user',['uid' => $ret['id']]);
            $r_data = ['code'=>200];
            $this->ajaxReturn($r_data,'json');
        }
    }
}